// 目标: 封装接口请求方法
// request是request.js里封装自定义函数
import request from '@/utils/request'
import store from '@/store'

export const getAllChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}

// 经验: 函数内自己确定不了的值, 让外面传入
export const loginAPI = ({ mobile, code }) => {
  // 知识点: axios的data选项如果是一个JS对象,axios内部会帮你转成JSON字符串
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile: mobile,
      code: code
    }
  })
}
// 获取用户已选频道
export const getUserChannelListAPI = () => {
  return request({
    url: '/v1_0/user/channels',
    headers: {
      Authorization: `Bearer ${store.state.token} `
    }
  })
}
// 获取所有的文章列表
export const getArticleListAPI = ({ channel_id, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id,
      timestamp
    }
  })
}
